package wyh.mapper;

import org.apache.ibatis.annotations.*;
import wyh.pojo.Patient;
import wyh.pojo.ServiceRecord;
import wyh.pojo.ServiceRecord2;

import java.util.List;

@Mapper
public interface ServiceRecordMapper {

    // 根据姓名模糊查询信息
    @Select("SELECT * FROM servicerecord WHERE 666666666666 LIKE CONCAT('%', #{name}, '%')")
    List<Patient> MappergetByNameLike(String name);


    /**
     * 查询出所有服务记录，并显示对应的关联陪诊员、关联患者、预约日期以及服务记录表的全部字段
     */
    @Select("SELECT\n" +
            "    sr.*,\n" +
            "    p.name AS patient_name,\n" +
            "    e.name AS escort_name\n" +
            "FROM\n" +
            "    servicerecord sr\n" +
            "        LEFT JOIN\n" +
            "    patientinfo p ON sr.patientId = p.patientId\n" +
            "        LEFT JOIN\n" +
            "    escortinfo e ON sr.escortId = e.escortId;")
    List<ServiceRecord2> MappergetAll2();//关联查询

    @Select("SELECT * FROM servicerecord")
    List<ServiceRecord> MappergetAll();

    @Delete("DELETE FROM servicerecord WHERE servicerecordId = #{serviceRecordId}")
    int MapperdeleteById(int serviceRecordId);

    @Update("UPDATE servicerecord " +
            "SET appointmentId = #{appointmentId}, " +
            "patientId = #{patientId}, " +
            "escortId = #{escortId}, " +
            "serviceStartTime = #{serviceStartTime}, " +
            "serviceEndTime = #{serviceEndTime}, " +
            "serviceContent = #{serviceContent}, " +
            "serviceEvaluation = #{serviceEvaluation}, " +
            "serviceFee = #{serviceFee} " +
            "WHERE servicerecordId = #{serviceRecordId}")
    int MapperupdateById(ServiceRecord serviceRecord);

    @Insert("INSERT INTO servicerecord (appointmentId, patientId, escortId, serviceStartTime, serviceEndTime, serviceContent, serviceEvaluation, serviceFee) " +
            "VALUES (#{appointmentId}, #{patientId}, #{escortId}, #{serviceStartTime}, #{serviceEndTime}, #{serviceContent}, #{serviceEvaluation}, #{serviceFee})")
    int MapperaddServiceRecord(ServiceRecord serviceRecord);

    @Select("SELECT * FROM servicerecord WHERE servicerecordId = #{serviceRecordId}")
    ServiceRecord MappergetById(int serviceRecordId);
}